package org.component 
{
	import flash.display.MovieClip;
	import flash.events.MouseEvent;
	import flash.text.TextField;
	
	import org.component.events.ListEvent;
	import org.component.item.ClistItem;
	
	import com.peachcastle.core.Display;
	
	/**
	 * ...
	 * @author kevin
	 */
	public class ComboBox extends Display
	{
		private var _items:Array = null;
		private var _list:Clist = null;
		private var _curr:TextField = null;
		private var _button:Button = null;
		
		public function ComboBox(ui:MovieClip = null, items:Array = null) 
		{
			_items = items;
			super(ui);
		}
		
		override protected function initialization():void 
		{
			super.initialization();
			assest.stop();

			_button = new Button(assest['button']);
			_curr = assest['button']['label'];
			_curr.text = _items[0];
			_list = new Clist(assest, ClistItem, _items, 1, _items.length, 19);
			_list.hide();
		}
		
		override protected function configEventListeners():void 
		{
			super.configEventListeners();
			
			_button.addEventListener(MouseEvent.CLICK, changeHandle);
			_list.addEventListener(ListEvent.LIST_SELECT, onSelectList);
		}
		
		private function changeHandle(e:MouseEvent):void
		{
			if (_list.isShow())
			{
				_list.hide();
			}else
			{
				_list.show();
			}
		}
		
		private function onSelectList(event:ListEvent):void
		{
			_curr.text = event.data;
			
			var evt:ListEvent = new ListEvent(ListEvent.LIST_SELECT);
			evt.data = event.data;
			dispatchEvent(evt);
			evt = null;
			
			_list.hide();
		}
	}

}